package com.shiwaixiangcun.monitor.dto;



import com.shiwaixiangcun.core.exceptions.MonkeyException;
import com.shiwaixiangcun.core.utils.MonkeyUtils;
import com.shiwaixiangcun.core.utils.SpringUtils;
import com.shiwaixiangcun.monitor.domain.WorkOrderCategory;
import com.shiwaixiangcun.monitor.enums.PriorityLevel;
import com.shiwaixiangcun.monitor.enums.WorkOrderStatus;
import com.shiwaixiangcun.monitor.service.WorkOrderCategoryService;

import java.util.List;

/**
 * Created by Administrator on 2017/4/20.
 */
public class WorkOrderQueryDto {

    public static  final String WORKORDER_TIMEOUT = "isTimeOut"; // 超时的
    public static  final String WORKORDER_ACCEPTED = "accepted"; // 我受理的
       public static  final String WORKORDER_COMMITED = "commited";  // 我创建的工单
    public static  final String WORKORDER_ALL = "all";  // 全部工单

    private WorkOrderCategoryService workOrderCategoryService;

    public WorkOrderQueryDto() {
        workOrderCategoryService = SpringUtils.getBean(WorkOrderCategoryService.class);
    }

    private String chose;

    private PriorityLevel priorityLevel; // 工单等级

    private WorkOrderStatus workOrderStatus; // 工单状态 (待接-完结-受理中)

    private Long categoryId; //分类id

    private List<Long> categoryChildIds ;

    private String searchKeyWord; //收索关键字

    public WorkOrderStatus getWorkOrderStatus() {
        return workOrderStatus;
    }

    public void setWorkOrderStatus(WorkOrderStatus workOrderStatus) {
        this.workOrderStatus = workOrderStatus;
    }

    public Long getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
        if (categoryId == null){
            return;
        }
        WorkOrderCategory one = workOrderCategoryService.findOne(categoryId);
        if(MonkeyUtils.isEmpty(one)){
            throw new MonkeyException("error", "分类不存在");
        }
        List<Long> childrenIds = workOrderCategoryService.findChildrenIds(one);
        childrenIds.add(categoryId);
        setCategoryChildIds(childrenIds);
    }


    public String getSearchKeyWord() {
        return searchKeyWord;
    }

    public void setSearchKeyWord(String searchKeyWord) {
        this.searchKeyWord = searchKeyWord.trim();
    }


    public String getChose() {
        return chose;
    }

    public void setChose(String chose) {
        this.chose = chose;
    }

    public PriorityLevel getPriorityLevel() {
        return priorityLevel;
    }

    public void setPriorityLevel(PriorityLevel priorityLevel) {
        this.priorityLevel = priorityLevel;
    }

    public List<Long> getCategoryChildIds() {
        return categoryChildIds;
    }

    public void setCategoryChildIds(List<Long> categoryChildIds) {
        this.categoryChildIds = categoryChildIds;
    }

    }
